<template>
    <div>
            <Card>
                <p slot="title">
				    添加版本
			    </p>
                <div>
                    <Form class="step-form" ref="dicData" :model="dicData" :rules="dicDataRules" :label-width="100">
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="数据编号：" prop="dataCode" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="dicData.dataCode" type="text" placeholder="请输入数据编号" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="字典数据：" prop="dataValue" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="dicData.dataValue" type="text" placeholder="请输入字典数据" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <FormItem >
                            <Button :disabled="hasSubmit" @click="addData" style="width:100px;" type="primary">提交</Button>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <Button :disabled="hasSubmit" @click="goBack" style="width:100px;" >返回</Button>
                        </FormItem>
                    </Form>
                </div>
            </Card>
    </div>
</template>

<script>
import ajax from '../../../libs/axios.js'
export default {
    name: 'addUser',
    data () {
        return {
            testModelShow:false,
            typeId:'',
            symptomList:[],
            selectModel:[],
            dicData: {
                typeId:'',
                dataCode:'',
                dataValue:''
            },
            dicDataRules: {
                dataCode: [
                    { required: true, message: '请输入数据编号', trigger: 'blur'},
                    {type: 'string', max: 15, message: '不能超过15个字符', trigger: 'blur'}
                ],
                dataValue: [
                    { required: true, message: '请输入字典数据', trigger: 'blur'},
                    {type: 'string', max: 15, message: '不能超过15个字符', trigger: 'blur'}
                ]
            },
            hasSubmit: false
        }
    },
    methods: {
        // 数据初始化
        init () {
            this.$store.commit('setActiveName', 'dictypeindex');
            var typeId = this.$route.params.id;
            this.dicData.typeId = typeId;
            this.typeId = typeId;
        },
        // 修改数据
        addData () {
            let that = this
            that.$refs['dicData'].validate((valid) => {
                if (valid) {
                    that.hasSubmit = true
                    let url = 'adminlogin/dic/addDicDataInfo'
                    let data = that.dicData
                    ajax.formRes(url, data).then(res => {
                        // success
                        that.$Message.success('新增数据成功,页面正在跳转')
                        that.hasSubmit = false
                            let argu = {
                                id:that.typeId
                            }
                            that.$router.push({
                                name: 'dicdataindex',
                                params: argu
                            })
                    }).catch(res => {
                        console.log('有错误信息')
                        // fail
                    })
                } else {
                    console.log('新增失败123123。。。')
                }
            })
        },
        goBack () {
            this.$router.push({
                name: 'appversionindex'
            })
        }
        
    },
    created: function () {
        this.init()
    },
    activated: function () {
        this.init()
    }
}
</script>
<style>
    .demo-upload-list-cover{
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,.6);
    }
    .card-upload:hover .demo-upload-list-cover{
        display: block;
    }
    .demo-upload-list-cover i{
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }
    .demo-spin-icon-load{
        animation: ani-demo-spin 1s linear infinite;
    }
    @keyframes ani-demo-spin {
        from { transform: rotate(0deg);}
        50%  { transform: rotate(180deg);}
        to   { transform: rotate(360deg);}
    }
    .demo-spin-col{
        height: 100px;
        position: relative;
        border: 1px solid #eee;
    }
</style>

